package com.mz.ozy.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.bean.MyCardBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class ExChangeAdapter extends RecyclerViewAdapter<MyCardBean.PageBean.PageItemsBean, ExChangeAdapter.ExChangeHolder> {

    private int type;

    public ExChangeAdapter(Context mContext, List<MyCardBean.PageBean.PageItemsBean> dataList, int type) {
        super(mContext, dataList);
        this.type = type;
    }

    @NonNull
    @Override
    public ExChangeAdapter.ExChangeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.item_brand_crad, parent, false);
        return new ExChangeHolder(itemView);
    }

    @Override
    public void onBindHolder(ExChangeAdapter.ExChangeHolder holder, MyCardBean.PageBean.PageItemsBean dataItem, int position) {
        holder.tvMoney.setText(dataItem.getAmt());
        holder.tvName.setText(dataItem.getCardname());
        holder.tvType.setText("规格: " + dataItem.getName());
        holder.tvData.setText("有效时间: " + dataItem.getStarttime() + "-" + dataItem.getEndtime());

        if (dataItem.getState() == 1) {
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.c_363636));
            holder.tvType.setTextColor(mContext.getResources().getColor(R.color.c_363636));
            holder.linearLayout.setBackgroundResource(R.mipmap.card_pre);
        } else {
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.c_a5a5a5));
            holder.tvType.setTextColor(mContext.getResources().getColor(R.color.c_a5a5a5));
            holder.linearLayout.setBackgroundResource(R.mipmap.card_normal);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    static class ExChangeHolder extends RecyclerView.ViewHolder {

        TextView tvName;
        TextView tvType;
        TextView tvMoney;
        TextView tvData;
        LinearLayout linearLayout;

        public ExChangeHolder(View itemView) {

            super(itemView);
            linearLayout = itemView.findViewById(R.id.ll);
            tvMoney = itemView.findViewById(R.id.tv_money);
            tvData = itemView.findViewById(R.id.tv_data);

            tvName = itemView.findViewById(R.id.tv_name);
            tvType = itemView.findViewById(R.id.tv_type);
        }
    }
}
